import axios from 'axios';
import { ElMessage } from 'element-plus'
import NProgress from 'nprogress';
const interfine = axios.create({
    baseURL:'/app-dev',
    timeout:5000
})

interfine.interceptors.request.use(config => {
    NProgress.configure({ showSpinner: false });
    NProgress.start()
    // config.headers.haha = 111
    if(localStorage.getItem('UserToken')){
        config.headers.token = localStorage.getItem('UserToken');
        // console.log(config.headers.token)
    }

   
    // console.log(config)
    return config
})

interfine.interceptors.response.use((response) => {
    
    NProgress.done()
    const res = response
    if(res.status !== 2000 && res.status !== 200){
        ElMessage({
            message:'请求失败',
            type:'error'
        })
    }else{
        return res.data
        
    }
    


},(error)=>{
    ElMessage({
        message:error.message,
        type:'error'
    })
})

export default interfine;